package config

import (
	. "SinaNyaLite/views/window"
	"github.com/sirupsen/logrus"
	"github.com/spf13/viper"
	"runtime"
)

type Config struct {
	*viper.Viper
}

func init() {
	Init()
}

// GlobalConfig 默认全局配置
var GlobalConfig *Config

func Init() {
	GlobalConfig = &Config{
		viper.New(),
	}

	switch runtime.GOOS {
	case "linux":
		GlobalConfig.SetConfigName("application")
		GlobalConfig.SetConfigType("yaml")
		GlobalConfig.AddConfigPath(".")
		GlobalConfig.AddConfigPath("./config")

		err := GlobalConfig.ReadInConfig()
		if err != nil {
			logrus.WithField("config", "GlobalConfig").WithError(err).Panicf("unable to read global config")
		}
	default:
		account, password := LoginWindow()
		GlobalConfig.Set("bot.account", account)
		GlobalConfig.Set("bot.password", password)
	}
}
